package com.IO.practice;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

public class D03PaiXu {
    public static void main(String[] args) throws IOException {
        // FileInputStream fis = new FileInputStream("untitled\\aaa.txt");
        // StringBuilder s = new StringBuilder();
        // int i;
        // while ((i = fis.read()) != -1){
        //     s.append((char)i);
        // }
        // fis.close();
        //
        // String[] str = s.toString().split("-");
        // HashSet<String> set = new HashSet<>();
        // Collections.addAll(set,str);
        // StringBuilder sb = new StringBuilder();
        // for (String string : set) {
        //     sb.append(string).append("-");
        // }
        // String string = sb.toString();
        // String substring = string.substring(0, sb.length() - 1);
        // System.out.println(substring);
        // FileWriter fw = new FileWriter("untitled\\ccc.txt");
        // fw.write(substring);
        // fw.close();
        // fis.close();
        
        FileInputStream fis = new FileInputStream("untitled\\aaa.txt");
        StringBuilder sb = new StringBuilder();
        int i;
        while ((i = fis.read()) != -1){
            sb.append((char)i);
        }
        fis.close();
        
        Integer[] array = Arrays.stream(sb.toString().split("-")).map(Integer::parseInt).sorted().toArray(Integer[]::new);
        String string = Arrays.toString(array);
        String replace = string.replace(", ", "-");
        String substring = replace.substring(1, replace.length() - 1);
        System.out.println(substring);
        FileWriter fw = new FileWriter("untitled\\ccc.txt");
        fw.write(substring);
        fw.close();
    }
}
